package com.tinyseed.emcp.api.basicdata.rest;

import com.tinyseed.emcp.api.basicdata.model.IndustryInputDTO;
import com.tinyseed.emcp.api.basicdata.service.IndustryService;
import com.tinyseed.emcp.api.basicdata.transfer.IndustryTransfer;
import com.tinyseed.hmxx.common.base.BaseController;
import com.tinyseed.hmxx.common.base.PageData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/industry")
@Api("企业管理接口")
public class IndustryController extends BaseController {

    @Autowired
    IndustryService industryService;

    /**
     * 得到分页信息
     */
    @RequestMapping(value = "/page")
    @ResponseBody
    public ResponseEntity page(int size, int current, String industryName, String startCreateTime, String endCreateTime) {
        // 使用 Db 的 template 方法
        IndustryInputDTO industryInputDTO = new IndustryInputDTO();
        industryInputDTO.setIndustryName(industryName);
        industryInputDTO.setStartCreateTime(startCreateTime);
        industryInputDTO.setEndCreateTime(endCreateTime);
        PageData result = industryService.page(size, current, industryInputDTO);
        return new ResponseEntity<>(result, HttpStatus.OK);

    }

    @GetMapping(value = "list")
    @ApiOperation("分页查询")
    public ResponseEntity list(int size, int current) {
        return new ResponseEntity<>(industryService.findIndustryByPage(current, size), HttpStatus.OK);

    }

    /**
     * 保存
     */
    @PostMapping(value = "/save")
    @ResponseBody
    public ResponseEntity save(IndustryInputDTO industryInputDTO) {
        return new ResponseEntity<>(industryService.save(IndustryTransfer.INSTANCE.mapIn2Model(industryInputDTO)), HttpStatus.OK);

    }
    /**
     * 删除
     */
    @PostMapping(value = "/delete")
    @ResponseBody
    public ResponseEntity delete(Long id) {
        return new ResponseEntity<>(industryService.delete(id), HttpStatus.OK);

    }

    @PostMapping(value = "optionList")
    @ResponseBody
    public ResponseEntity optionList() {
        return new ResponseEntity<>(industryService.getOptionList(), HttpStatus.OK);
    }

}
